<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
	<link rel="stylesheet" href="../../resource/weuimin.css"/>
	<link rel="stylesheet" href="../../resource/example.css"/>
    <script src="../resource/md5.js"></script>
    <script type="text/javascript" src="../../script/aes.js"></script>
	<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
	<script type="text/javascript" src="../../script/modeecb.js"></script>
	<script src="../../template/js/jquery.js"></script>
	<script src="../../template/js/com/template.js"></script>
	<script src="../../resource/my.js"></script>
	<script src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/tmd5.js"></script>
    <script type="text/javascript" src="../../script/constants.js"></script>
    <style>
    	body {
	    }
    	.bgColor {
    		
    	}
		
		.btnn{
		 width:90%;
		 font-size:20px;
		 margin:0 auto;
		 height:42px;
		 border-radius:5px;
         line-height: 42px;
		}
		.xxleft{
		  float:right;
		  margin-left:10px;
		}
		.xxrigth{
		  float:left;
		  margin-right:10px;
		}
    </style>
</head>
<body style="background: #f0f0f0"> 
<div>
	<div style="">
		<div style="width:100%;clear:both">
		<div style="font-size: 20px;float:left;padding-left:10px;height:40px;line-height:40px;width:60%"><img style="width:10%;margin-right:5px" src="../../image/tl.png"/>银联支付</div>
		
		<input type="button" onclick="closeInfo()" style="height:40px;line-height:40px;font-size:xx-large;float:right;margin-right:5%;" value="&times"/>
		</div>
	</div>
	<div style="clear:both;width:100%;">
		<div style="font-size:36px;text-align:center;margin-bottom: 20px;" id="je"></div>
		<div>
		<div style="clear:both;width:100%;margin-bottom:5px;">
		<div style="float:left;margin-left:10px;font-size:15px;color:#9d9d9d">订单信息</div>
		<div style="float:right;margin-right:10px;font-size:15px;text-align: center;" id="spms">酒店预订</div>
		</div>
         </div>
         <div>
		<div style="clear:both;width:100%;">
		<div style="float:left;margin-left:10px;font-size:16px;color:#9d9d9d;margin-top: 20px;">支付卡号</div>
		<div style="float:right;margin-right:10px;font-size:16px;margin-top: 20px;" id="cardNo"></div>
		</div>
         </div>
				</div>
	
		</div>
		<div style="bottom:0;position:absolute;width:100%">
		<div style="text-align:center;margin-bottom:20px;">
		<div id="btnn" class="btnn" onclick="unionPay();" style="background: #18b4ed;color:#fff">立即支付</div>
		</div>
		</div>
		<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据提交中...</p>
			</div>
		</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../resource/jquery1.js"></script>
<script type="text/javascript">
    var orderid = "";
    var seli = 1;
    var zje;
    var bsh = "2";
	var bdzdh = "2";
	var bkhh = "2";
	var bfplx = "2";
	var bmc = "2";
	var amc = "2";
	var adh = "2";
	var adz = "2";
	var dzObj = null;
	var num = 2;
	var allPrice;
	var allspmc = "2";
	var merid = "";
	apiready = function(){
	  allPrice = api.pageParam.zje;
	  merid = api.pageParam.merid;
      orderid = api.pageParam.orderid;
      //console.info(orderid+","+amc+","+adh+","+adz+","+bmc+","+bsh+","+bdzdh+","+bkhh+","+bfplx+","+allPrice);
	  var money = changeDecimalBuZero(allPrice,2);
	  var card = $api.getStorage("card");
	  adz = adz.replace(/,/g,'_');
	  $("#je").html("￥"+money+"元");
	  //$("#spms").html(allspmc);
	  $("#cardNo").html(card);
	};
	function closeInfo(){
		if(api.systemType == "android"){
		 $api.setStorage("upay","");
		 }
		var jsfun = 'funcGoto();';
		api.execScript({
		    script: jsfun
		});
		api.closeFrame({
	    });
	    
	}
	
	var bookId = "";
	
	var qr;
	var time;
	var ddh;
   	function unionPay(){
   	   	$("#loadingToast").show();
  		var _openid = $api.getStorage('openid');
  		var dl_phone = $api.getStorage("dl_phone");
  		var ip = "0.0.0.0";
		var ipAddr = api.require('ipAddress');
		var s = api.connectionType;
	    s = s.toLowerCase();
	    ipAddr.getIp(
		function(ret, err) {
			if (ret.status) {
				ip = ret.ip;
	
      var aeskey = api.loadSecureValue({
        sync: true,
        key: 'aeskey'
      });
      var salt = api.loadSecureValue({
		    sync: true,
		    key: 'salt'
		});
      var content = {"dlPhone":dl_phone,"ip":ip,"deviceID":api.deviceId,"openid":_openid,"orderid":orderid,"je":allPrice,"merid":merid,"deviceName":api.deviceName,"jdid":$api.getStorage('jdid')};
 
      var sign = md5(JSON.stringify(content)+salt);
      var p = {"sign":sign,"content":JSON.stringify(content)};
      var para = Encrypt(JSON.stringify(p),aeskey);
       var callback = function(data, err){
          console.log(JSON.stringify(data));
       	  if("N"==data.flag){
		    	$("#loadingToast").hide();
		       if(api.systemType=='ios'){
		        api.confirm({
		          title: '温馨提示',
		          msg:'对不起，您还没绑定银行卡，请先绑定银行卡！',
		          buttons: ['去绑卡', '暂时不用']
		        }, function(ret, err) {
		          var index = ret.buttonIndex;
		          if(index==1){
		          api.openWin({
						name: 'card',
		                url:url.xzyhk+"?dlPhone="+dl_phone
		                });
		          }else if(index==2){
		            
		          }
		        });
		      }else{
		        var r=confirm("您还没有绑卡哦，确定现在去绑卡吗？");
		        if(r){
		          api.openWin({
						name: 'card',
		                url:url.xzyhk+"?dlPhone="+dl_phone
		          });
		        }else{
		          
		        }
		      }
		     }else if(data.flag == "Y"){
		       bookId = data.payid;
		       qr = data.qrNo;
			   time = setInterval("zfNotify()",2000);
//		       api.openWin({
//	              name: 'success',
//	              url: 'success.html',
//	              pageParam: {
//						id:qr,
//						amt:'239',
//						zt:1
//				  }
//            });
		     }else{
		        $("#loadingToast").hide();
		        alert(data.msg);
		        api.closeFrame();
		     }
        }
	    apiAjax(JSON.stringify(content),url.jdidPayOrder,callback);
	    }
		});
   	}
   	
  function zfNotify(){
//    var callback = function(data, err){
//    if(data != null){
//    		var no;
//	        var je;
//	        if (data.msg == "成功") {	
//	         $("#loadingToast").hide();
//	          localStorage.setItem("ShoppingCart", "");
//	          clearInterval(time);
//	          api.openWin({
//	              name: 'success',
//	              url: 'success.html',
//	              pageParam: {
//						id:orderid,
//						amt:allPrice,
//						zt:1
//				  }
//            });
//	        }else{
//	         $("#loadingToast").hide();
//	          clearInterval(time);
//	          var msgc = data.MSG;
//	          api.openWin({
//	              name: 'success',
//	              url: 'success.html',
//	              pageParam: {
//						msg:msgc,
//						zt:2
//				  }
//            });
//	        }
//      }
//      }
//	    var parameter = {"ddh":ddh};
//	    apiAjax(JSON.stringify(parameter),url.jdydCxzf,callback);
	    
	   var callback = function(data, err){
            //console.log(JSON.stringify(data));
          if(data){
	        if (data.MSG == "成功") {	
	          var no = data.NO;
	          var je = data.AMT;
	         $("#loadingToast").hide();
	          localStorage.setItem("ShoppingCart", "");
	          clearInterval(time);
	          api.openWin({
	              name: 'success',
	              url: 'success.html',
	              pageParam: {
						id:no,
						amt:je,
						zt:1
				  }
              });
	  	    var callback = function(ret, err){
	            //console.log(JSON.stringify(ret));
		        }
		    var parameter = {"bookid":bookId};
	        apiAjax(JSON.stringify(parameter),url.jdPaySuccess,callback);
	        }else{
	         $("#loadingToast").hide();
	          clearInterval(time);
	          var msgc = data.MSG;
	          api.openWin({
	              name: 'success',
	              url: 'success.html',
	              pageParam: {
						msg:msgc,
						zt:2
				  }
              });
	        }
        }
    }
    var content = {"qrno":qr};
    apiAjax(JSON.stringify(content),url.zczfjg,callback);
}

 function changeDecimalBuZero(number, bitNum) {  
           /// <summary>  
           /// 小数位不够，用0补足位数  
           /// </summary>  
           /// <param name="number">要处理的数字</param>  
           /// <param name="bitNum">生成的小数位数</param>  
           var f_x = parseFloat(number);  
           if (isNaN(f_x)) {  
               return 0;  
           }  
           var s_x = number.toString();  
           var pos_decimal = s_x.indexOf('.');  
           if (pos_decimal < 0) {  
               pos_decimal = s_x.length;  
               s_x += '.';  
           }  
           while (s_x.length <= pos_decimal + bitNum) {  
               s_x += '0';  
           }  
           return s_x;  
       }  
</script>
</html>